package com.example.springbootlearn.security.service;


import com.example.springbootlearn.security.mapper.UserMapper;
import com.example.springbootlearn.security.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserService implements UserDetailsService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userMapper.loadByUserName(username);
        user.setRoles(userMapper.loadRolesByUid(user.getId()));

        return user;
    }
}
